import confirm, { ConfirmResult } from '@dfeidao/atom-web/msgbox/confirm';

import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';

import s_get from '@dfeidao/atom-web/storage/get';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';

import get from '@dfeidao/atom-web/local/get';
import error from '@dfeidao/atom-web/msgbox/error';
import success from '@dfeidao/atom-web/msgbox/success';
interface Aa {
	id: string;
	p_id: string;
	flag: number;
	client_point_id: string;
	client_style: string;
}


export default async function a004(fd: IFeidaoAiBrowserComponent) {
	// 删除


	const productid = await s_get('productid');
	const curr_dept = get(fd, 'curr_dept') as Aa;
	// const dataFlag: number = get(fd, 'dataFlag');
	// const client_point_id: string = get(fd, 'client_point_id');
	// const formid: string = get(fd, 'formid');


	if (!curr_dept || !curr_dept.id) {
		// await error('');
		error('请先选中一条数据');
		return;
	}

	// if (dataFlag === 0) {
	// 	error('请先选择末级菜单删除');

	// 	return;
	// }
	const menu_no = curr_dept.id;

	// const client_type = client_point_id;
	if (menu_no && productid) {
		const res2 = await nodejs<{ length: number }>('menu/zj-000001/s011', { menu_no, productid });
		// console.log(res2.length, '000');
		// debugger;
		if (res2.length > 0) {
			error('请选择末级菜单删除！');
			return;
		} else {
			const flag = await confirm('您确定要删除此菜单吗？', '提示', '是', '否');
			switch (flag) {
				case ConfirmResult.YES:
					const res1 = await nodejs('menu/zj-000001/s004', { menu_no, productid });
					// debugger;
					if (res1 === 'success') {
						fire('zj-000001', 'ec-001');
						success('删除菜单成功');

					} else if (res1 === 'fail') {
						error('删除菜单失败');
						return;
					} else {
						error('该菜单关联了权限页面，不允许删除');
						return;
					}
					break;
				case 'no':
					// 点击否要做的操作
					// todo
					break;
				default:
					// cancel
					// todo
					break;
			}
		}

	}

}
